package iterables;

import java.util.*;

public class IterablesConcatenados<T> implements Iterable<T>{
	  private Iterable <T> it1;
	  private Iterable <T> it2;

	  public IterablesConcatenados(Iterable<T> i1, Iterable<T> i2){
	  	it1=i1;
	  	it2=i2;
	  }
	  
	  public Iterator<T> iterator(){
	  	return new IteradorConcatenado(it1.iterator(),it2.iterator());
	  } 

	  private class IteradorConcatenado implements Iterator<T>{
		  private Iterator <T> it1;
		  private Iterator <T> it2; 
		  public IteradorConcatenado(Iterator <T> i1, Iterator <T> i2) {
		   it1 = i1;
		   it2 = i2;
		   }
		  public boolean hasNext() {
		    return it1.hasNext()||it2.hasNext();
		  }
		  public T next() {
		    T aux;
		    if(it1.hasNext()){
		      aux = it1.next();
		    }else{
		      aux = it2.next();
		    }
		  return aux;
		  }
		  public void remove() {
		  }
		}
}


